package com.zhouxin.customview.view

import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Path
import android.util.AttributeSet
import android.view.View
import com.zhouxin.customview.extensions.dp2px


/**
 * Copyright©
 * FileName: TestView
 * Author: ZhouXin
 * Date: 2022/6/2
 * Description: 自定义View
 */
private val RADIUS = 100f.dp2px;
class TestView(context: Context?, attrs: AttributeSet?) : View(context, attrs) {
    //开启抗锯齿
    private val paint = Paint(Paint.ANTI_ALIAS_FLAG)
    private val path = Path()

    override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
        path.reset()
        path.addCircle(width / 2f, height / 2f, RADIUS, Path.Direction.CW)
        path.addRect(width / 2f - RADIUS, height / 2f, width / 2f + RADIUS, height / 2f + 2* RADIUS, Path.Direction.CCW)
        path.addCircle(width / 2f, height / 2f, RADIUS * 1.5f, Path.Direction.CW)
        path.fillType = Path.FillType.EVEN_ODD
    }

    override fun onDraw(canvas: Canvas) {
//        canvas.drawLine(100f, 100f, 200f, 200f, paint)
//        canvas.drawCircle(width / 2f, height / 2f, RADIUS, paint)
        canvas.drawPath(path, paint)
    }
}